class Mobile::Apps::FoodsController < ApplicationController
    layout 'app'
    include PrintOrder
    
    def index
        @orders = Order.all
    end    

    def show
        @order = Order.find params[:id]
    end    

    def pay
        @order = Order.find params[:id]
        @order.is_pay = true
        @order.save
        content = generate_content order
        printers_print @order.restaurant,content
        redirect_to action: :show,id: @order.id
    end    

    def print
        @order = Order.find params[:id]
        content = generate_content order
        printers_print @order.restaurant,content
        redirect_to action: :show,id: @order.id
    end    

    # private
    # def reprint_order order
    #     #标签说明："<BR>"为换行符,"<CB></CB>"为居中放大,"<B></B>"为放大,"<C></C>"为居中,"<L></L>"为字体变高
    #   #"<W></W>"为字体变高,"<QR></QR>"为二维码,"<CODE>"为条形码,后面接12个数字
      
    #     content = '<CB>测试打印</CB><BR>'
    #     content += '名称　　　　　 单价  数量 金额<BR>'
    #     content += '--------------------------------<BR>'
    #     order.order_items.each do |line_item|
    #       content += "#{line_item.food_name}　　　　　 　#{line_item.single_price}   #{line_item.quantity}  #{line_item.total_price}<BR>"    
    #       content += '--------------------------------<BR>'
    #     end
    #     content += "合计：#{order.total_price}元<BR>"
    #     content += '<BR>'
    #     content += "<C><QR>#{"http://xuzhaolin.s1.natapp.cc"}</QR></C>"
    #     content += "<PLUGIN>您有新的订单</PLUGIN>"
    #     params = {}
    #     params["sn"] = PRINTER_SN  
    #     params["content"] = content #打印内容 
    #     params["times"] = "1" #打印联数 
    #     params["apiname"] = "Open_printMsg"
    #     stime = Time.now.to_i
    #     params['stime'] = stime
    #     params['user'] = 'zhaolin.xu@gmail.com'
    #     key = Digest::SHA1.hexdigest "zhaolin.xu@gmail.comVkMwj5GbzFAd6ZTk#{stime}"
    #     params["sig"] = key
    #     uri = URI.parse(IP)
    #     res = Net::HTTP.post_form(uri, params)
    #     puts res.body
    # end    
end
